package com.pearl.shardingsphere.rw.controller;

import cn.hutool.core.util.IdUtil;
import com.pearl.shardingsphere.rw.entity.OrderEntity;
import com.pearl.shardingsphere.rw.service.OrderService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 订单信息表 前端控制器
 * </p>
 *
 * @author 自动代码生成
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;
    @GetMapping("/list")
    public List<OrderEntity> list() {
        return orderService.list();
    }

    @GetMapping("/save")
    public Object save() {
        OrderEntity orderEntity=new OrderEntity();
        orderEntity.setId(IdUtil.getSnowflakeNextId());
        orderEntity.setPhone(18888888888L);
        orderEntity.setAddress("湖南长沙");
        orderEntity.setOrderTime(LocalDateTime.now());
        orderEntity.setProductId(1L);
        orderEntity.setOrderTime(LocalDateTime.now());
        orderEntity.setId(IdUtil.getSnowflakeNextId());
        orderService.save(orderEntity);
        return "操作成功";
    }

/*    private final TOrderService tOrderService;

    private final TOrderMapStructMapper tOrderMapStructMapper;

    @Operation(summary = "单个新增")
    @PostMapping("/save")
    public Result<?> save(@RequestBody @ParameterObject TOrderSaveForm tOrderSaveForm) {
        tOrderService.save(tOrderMapStructMapper.tOrderSaveForm2Entity(tOrderSaveForm));
        return Result.success();
    }

    @Operation(summary = "批量新增")
    @PostMapping("/saveBatch")
    public Result<?> saveBatch(@RequestBody @ParameterObject List<TOrderSaveForm> tOrderSaveFormList) {
        tOrderService.saveBatch(tOrderMapStructMapper.tOrderSaveForm2Entity(tOrderSaveFormList));
        return Result.success();
    }

    @Operation(summary = "根据ID删除")
    @DeleteMapping("/remove/{id}")
    public Result<?> removeById(@PathVariable("id") Long id) {
        tOrderService.removeById(id);
        return Result.success();
    }

    @Operation(summary = "根据ID集合批量删除")
    @DeleteMapping("/remove/{ids}")
    public Result<?> removeByIds(@PathVariable("ids") List<Long> ids) {
        tOrderService.removeByIds(ids);
        return Result.success();
    }

    @Operation(summary = "修改")
    @PutMapping("/update")
    public Result<?> update(@RequestBody @ParameterObject TOrderUpdateForm tOrderUpdateForm) {
        tOrderService.updateById(tOrderMapStructMapper.tOrderUpdateForm2Entity(tOrderUpdateForm));
        return Result.success();
    }

    @Operation(summary = "根据ID查询")
    @GetMapping("/get/{id}")
    public Result<TOrderVO> getById(@PathVariable("id") Long id) {
        return Result.success(tOrderMapStructMapper.tOrderEntity2VO(tOrderService.getById(id)));
    }


    @Operation(summary = "条件查询（不分页）")
    @GetMapping("/list")
    public Result<List<TOrderVO>> list(@ParameterObject TOrderQuery tOrderQuery) {
        List<TOrderEntity> list = tOrderService.selectList(tOrderQuery);
        List<TOrderVO> result = tOrderMapStructMapper.tOrderEntity2VO(list);
        return Result.success(result);
    }*/
}